package com.tdwyz.fictionmanage.mapper;

import com.tdwyz.fictionmanage.pojo.Fiction;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FictionMapper {
    //新增小说
    @Insert("INSERT into fiction(title,author,introduction,titleUrl,cover_image,category_id,create_user,create_time,update_time)" +
            "values(#{title},#{author},#{introduction},#{titleUrl},#{coverImage},#{categoryId},#{createUser},now(),now())")
    boolean add(Fiction fiction);

    //根据小说id查询小说
    @Select("select * from fiction where id = #{id}")
    Fiction getById(Integer id);

    //更新小说
    @Update("update fiction set create_user=#{createUser},title=#{title},author=#{author},introduction=#{introduction},titleUrl=#{titleUrl},cover_image=#{coverImage}," +
            "category_id=#{categoryId},update_time=now() where id=#{id}")
    boolean update(Fiction fiction);

    //查询我的小说
    List<Fiction> listMy(Integer userId, Integer categoryId);

    //查询所有小说
    List<Fiction> list(Integer categoryId);

    //删除小说
    @Delete("delete from fiction where id = #{id}")
    boolean delete(Integer id);
}
